#include "gun.h"

gun::gun(std::string type) {
    this->type_ = type;
    this->current_bullet_count_ = 0;
}

void gun::addBullet(int num) {
    // if bullet_num more than max_bullet_count_
    if (current_bullet_count_ == max_bullet_count_) {
        std::cout << "Box magazine is full, There is no need to add bullet!"
                  << std::endl;
        return;
    }
    // add bullet
    int sum_bullet_num = 0;
    sum_bullet_num = current_bullet_count_ + num;
    if (sum_bullet_num <= 50) {
        current_bullet_count_ += num;
        std::cout << "Add bullet successfully!" << std::endl;
        std::cout << "current_bullet_count_ is " << current_bullet_count_
                  << std::endl;
        return;
    } else {
        std::cout
            << "Box magazine overflows. Partial bullets are added successfully."
            << std::endl;
        std::cout << max_bullet_count_ - current_bullet_count_
                  << "bullets are added successfully! " << std::endl;
        std::cout << sum_bullet_num - max_bullet_count_
                  << "bullets are added failed! " << std::endl;
        std::cout << "current_bullet_count_ is " << current_bullet_count_
                  << std::endl;
        return;
    }
    // print info
}

void gun::shoot() {
    // if bullet_num less than 0
    if (current_bullet_count_ <= 0) {
        std::cout << "No more bullets, please add bullet!" << std::endl;
        return;
    }

    // shoot
    current_bullet_count_ -= 1;

    // print info
    std::cout << "shoot one bullet..." << std::endl;
    std::cout << "shoot successfully!" << std::endl;
    std::cout << "current_bullet_count_ is " << current_bullet_count_
              << std::endl;
}